home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / system.c,v < prev    next >
Encoding:
Text File  |  1989-03-22  |  3.5 KB  |  193 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     89.03.22.00.47.35;  author rab;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     88.10.06.15.11.53;  author ouster;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     88.07.29.17.04.34;  author ouster;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     88.07.25.14.18.38;  author ouster;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     88.06.05.13.14.30;  author ouster;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     88.05.21.17.31.01;  author ouster;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 1.6
  45. log
  46. @*** empty log message ***
  47. @
  48. text
  49. @/* 
  50.  * system.c --
  51.  *
  52.  *    Source code for the "system" library procedure.
  53.  *
  54.  * Copyright 1988 Regents of the University of California
  55.  * Permission to use, copy, modify, and distribute this
  56.  * software and its documentation for any purpose and without
  57.  * fee is hereby granted, provided that the above copyright
  58.  * notice appear in all copies.  The University of California
  59.  * makes no representations about the suitability of this
  60.  * software for any purpose.  It is provided "as is" without
  61.  * express or implied warranty.
  62.  */
  63.  
  64. #ifndef lint
  65. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/system.c,v 1.5 88/10/06 15:11:53 ouster Exp Locker: rab $ SPRITE (Berkeley)";
  66. #endif /* not lint */
  67.  
  68. #include <stdlib.h>
  69. #include <signal.h>
  70. #include <sys/wait.h>
  71.  
  72. /*
  73.  *----------------------------------------------------------------------
  74.  *
  75.  * system --
  76.  *
  77.  *    Pass a string off to "sh", and return the result of executing
  78.  *    it.
  79.  *
  80.  * Results:
  81.  *    The return value is the status returned by "sh".
  82.  *
  83.  * Side effects:
  84.  *    None.
  85.  *
  86.  *----------------------------------------------------------------------
  87.  */
  88.  
  89. int
  90. system(command)
  91.     char *command;        /* Shell command to execute. */
  92. {
  93.     int pid, pid2, result;
  94.     struct sigvec quitHandler, intHandler;
  95.     static struct sigvec newHandler = {SIG_IGN, 0, 0};
  96.     union wait status;
  97.  
  98.     sigvec(SIGINT, &newHandler, &intHandler);
  99.     sigvec(SIGQUIT, &newHandler, &quitHandler);
  100.  
  101.     pid = fork();
  102.     if (pid == 0) {
  103.     execlp("sh", "sh", "-c", command, 0);
  104.     _exit(127);
  105.     }
  106.     while (1) {
  107.     pid2 = wait(&status);
  108.     if (pid2 == -1) {
  109.         result = -1;
  110.         break;
  111.     }
  112.     if (pid2 == pid) {
  113.         result = status.w_status;
  114.         break;
  115.     }
  116.     }
  117.     sigvec(SIGINT, &intHandler, (struct sigvec *) 0);
  118.     sigvec(SIGQUIT, &quitHandler, (struct sigvec *) 0);
  119.     return result;
  120. }
  121. @
  122.  
  123.  
  124. 1.5
  125. log
  126. @Wasn't returning correct status:  should be all 16 bits, not just
  127. return code.
  128. @
  129. text
  130. @d17 2
  131. a18 2
  132. static char rcsid[] = "$Header: system.c,v 1.4 88/07/29 17:04:34 ouster Exp $ SPRITE (Berkeley)";
  133. #endif not lint
  134. d20 1
  135. @
  136.  
  137.  
  138. 1.4
  139. log
  140. @Lint.
  141. @
  142. text
  143. @d17 1
  144. a17 1
  145. static char rcsid[] = "$Header: system.c,v 1.3 88/07/25 14:18:38 ouster Exp $ SPRITE (Berkeley)";
  146. d64 1
  147. a64 1
  148.         result = status.w_T.w_Retcode;
  149. @
  150.  
  151.  
  152. 1.3
  153. log
  154. @Bug:  typed "==" instead of "=".
  155. @
  156. text
  157. @d17 1
  158. a17 1
  159. static char rcsid[] = "$Header: system.c,v 1.2 88/06/05 13:14:30 ouster Exp $ SPRITE (Berkeley)";
  160. d68 2
  161. a69 2
  162.     sigvec(SIGINT, &intHandler, 0);
  163.     sigvec(SIGQUIT, &quitHandler, 0);
  164. @
  165.  
  166.  
  167. 1.2
  168. log
  169. @Bad declaration;  wasn't caught until I switched to Gcc.
  170. @
  171. text
  172. @d17 1
  173. a17 1
  174. static char rcsid[] = "$Header: system.c,v 1.1 88/05/21 17:31:01 ouster Exp $ SPRITE (Berkeley)";
  175. d60 1
  176. a60 1
  177.         result == -1;
  178. @
  179.  
  180.  
  181. 1.1
  182. log
  183. @Initial revision
  184. @
  185. text
  186. @d17 1
  187. a17 1
  188. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  189. d47 1
  190. a47 1
  191.     struct wait status;
  192. @
  193.